package com.ruoyi.cloudpc.controller;

import com.ruoyi.cloudpc.domain.CloudDevice;
import com.ruoyi.cloudpc.service.ICloudDeviceService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 设备Controller
 *
 * @author Ten
 * @date 2025-09-20
 */
@RestController
@RequestMapping("/cloudpc/device")
public class CloudDeviceController extends BaseController {
    @Autowired
    private ICloudDeviceService cloudDeviceService;

    /**
     * 查询设备列表
     */
    @GetMapping("/list")
    public TableDataInfo list(CloudDevice cloudDevice) {
        startPage();
        List<CloudDevice> list = cloudDeviceService.selectCloudDeviceList(cloudDevice);
        return getDataTable(list);
    }

    /**
     * 导出设备列表
     */
    @Log(title = "设备", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CloudDevice cloudDevice) {
        List<CloudDevice> list = cloudDeviceService.selectCloudDeviceList(cloudDevice);
        ExcelUtil<CloudDevice> util = new ExcelUtil<>(CloudDevice.class);
        util.exportExcel(response, list, "设备数据");
    }

    /**
     * 获取设备详细信息
     */
    @GetMapping(value = "/{orderId}")
    public AjaxResult getInfo(@PathVariable("orderId") Long orderId) {
        return success(cloudDeviceService.selectCloudDeviceByOrderId(orderId));
    }

    /**
     * 新增设备
     */
    @Log(title = "设备", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CloudDevice cloudDevice) {
        return toAjax(cloudDeviceService.insertCloudDevice(cloudDevice));
    }

    /**
     * 修改设备
     */
    @Log(title = "设备", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CloudDevice cloudDevice) {
        return toAjax(cloudDeviceService.updateCloudDevice(cloudDevice));
    }
}
